package o;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnShowListener;
import android.text.Editable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.gamebox.plugin.gameservice.bean.RealName;
import com.huawei.gamebox.plugin.gameservice.bean.RealNameParam;
import com.huawei.gamebox.support.widget.ErrorTipTextLayout;
import com.huawei.hms.framework.common.ContainerUtils;
import java.util.regex.Pattern;
import BaseDialog.a;
import o.exp.d;
import o.exp.j;

public class fao extends BaseAlertDialog implements OnShowListener, OnDismissListener, TextWatcher {
    private fao ʻ;
    private boolean ʻॱ;
    private GameInfo ʼ;
    private RealNameParam ʽ;
    private djl ˊॱ;
    private ScrollView ˋ;
    private ErrorTipTextLayout ˋॱ = null;
    private RelativeLayout ˎ;
    private EditText ˏॱ = null;
    private ErrorTipTextLayout ͺ = null;
    private LinearLayout ॱ = null;
    private EditText ॱˊ = null;
    private fav ॱॱ;
    private TextView ॱᐝ = null;
    private Activity ᐝ;
    private ImageView ᐝॱ = null;

    fao(Activity activity, String str, CharSequence charSequence, GameInfo gameInfo, RealNameParam realNameParam, fav o_fav) {
        super(activity, str, charSequence);
        this.ᐝ = activity;
        this.ॱॱ = o_fav;
        this.ʽ = realNameParam;
        this.ʻ = this;
        this.ʼ = gameInfo;
    }

    public static fao ˊ(Activity activity, GameInfo gameInfo, RealNameParam realNameParam, fav o_fav) {
        if (activity == null) {
            return null;
        }
        String string = activity.getString(exp$f.ˋʼ);
        if (activity.isFinishing()) {
            return new faq(activity, string);
        }
        fao o_fao = new fao(activity, string, null, gameInfo, realNameParam, o_fav);
        try {
            o_fao.ˎ((Context) activity);
            return o_fao;
        } catch (Throwable e) {
            Logger.ˋ("RealNameAuthDialog", "RealNameAuthDialog exception", e);
            return null;
        }
    }

    void ˏ(int i, boolean z) {
        if (i == 70001202 || z) {
            if (!z || i == 70001201) {
                this.ͺ.setError(ezk.ॱ(this.ᐝ, 110033));
            } else {
                this.ͺ.setError(ezk.ॱ(this.ᐝ, 110034));
            }
            this.ˏॱ.requestFocus();
            this.ˋॱ.setError("");
        } else if (i == 70001201) {
            this.ˋॱ.setError(ezk.ॱ(this.ᐝ, 110033));
            this.ॱˊ.requestFocus();
            this.ͺ.setError("");
        }
        ˊ();
    }

    private void ʼ() {
        if (Logger.ˎ()) {
            Logger.ˏ("RealNameAuthDialog", "set error gone");
        }
        if (this.ˋॱ != null) {
            this.ˋॱ.setError("");
        }
        if (this.ͺ != null) {
            this.ͺ.setError("");
        }
    }

    void ˊ() {
        if (this.ˊॱ != null) {
            this.ˊॱ.dismiss();
        }
    }

    private void ˎ(Context context) {
        LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(context).inflate(j.ʼॱ, null);
        ˊ(linearLayout);
        this.ˋॱ = (ErrorTipTextLayout) linearLayout.findViewById(d.ˋᐝ);
        this.ͺ = (ErrorTipTextLayout) linearLayout.findViewById(d.ˎˎ);
        this.ॱˊ = (EditText) linearLayout.findViewById(d.ॱʾ);
        this.ॱˊ.addTextChangedListener(this);
        if (!(this.ʽ == null || this.ʽ.ˊ() == null || dof.ॱ(this.ʽ.ˊ().ˎ()))) {
            this.ॱˊ.setText(this.ʽ.ˊ().ˎ());
        }
        this.ˏॱ = (EditText) linearLayout.findViewById(d.ﹳ);
        this.ˏॱ.addTextChangedListener(this);
        if (!(this.ʽ == null || this.ʽ.ˊ() == null || dof.ॱ(this.ʽ.ˊ().ˊ()))) {
            this.ˏॱ.setText(this.ʽ.ˊ().ˊ());
        }
        this.ॱ = (LinearLayout) linearLayout.findViewById(d.ˌ);
        this.ˋ = (ScrollView) linearLayout.findViewById(d.ˊʽ);
        this.ˎ = (RelativeLayout) linearLayout.findViewById(d.ͺˎ);
        this.ᐝॱ = (ImageView) linearLayout.findViewById(d.ʿ);
        this.ॱᐝ = (TextView) linearLayout.findViewById(d.ˋʽ);
        ॱॱ();
    }

    public void ॱ() {
        this.ʻॱ = false;
        if (this.ᐝ == null || this.ᐝ.isFinishing()) {
            Logger.e("RealNameAuthDialog", "show dlg error");
            return;
        }
        try {
            ˊ(this);
            super.ॱ();
            ˎ(this);
            ॱ(false);
            ˊ(new OnClickListener(this) {
                final /* synthetic */ fao ˎ;

                {
                    this.ˎ = r1;
                }

                public void onClick(View view) {
                    this.ˎ.ʻॱ = true;
                    this.ˎ.ˊ(this.ˎ.ᐝ);
                }
            });
            ˋ(new OnClickListener(this) {
                final /* synthetic */ fao ˊ;

                {
                    this.ˊ = r1;
                }

                public void onClick(View view) {
                    this.ˊ.ʻॱ = false;
                    this.ˊ.ˏ();
                }
            });
            ॱ(a.ˋ, exp$f.ˊʻ);
        } catch (Throwable e) {
            Logger.ˋ("RealNameAuthDialog", "show dlg error, e: ", e);
        }
    }

    void ᐝ() {
        ˏ();
        if (this.ᐝ != null) {
            this.ᐝ.finish();
        }
    }

    public void onShow(DialogInterface dialogInterface) {
        if (this.ʽ == null || dof.ॱ(this.ʽ.ˎ())) {
            this.ᐝॱ.setVisibility(8);
            ˎ(0);
            return;
        }
        this.ᐝॱ.setVisibility(0);
        ˎ(epv.ˋ(this.ᐝ, 92));
        eqx.ˏ(this.ᐝॱ, this.ʽ.ˎ(), "app_default_icon");
    }

    public void onDismiss(DialogInterface dialogInterface) {
        if (!(this.ʻॱ || this.ॱॱ == null)) {
            this.ॱॱ.ˋ(2);
        }
        ˊ();
        if (this.ᐝ != null && !this.ᐝ.isFinishing()) {
            this.ᐝ.finish();
        }
    }

    public void afterTextChanged(Editable editable) {
    }

    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        ʼ();
    }

    public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    }

    private int ˎ(String str, String str2) {
        if (dof.ॱ(str)) {
            return 70001201;
        }
        if (dof.ॱ(str2)) {
            return 70001202;
        }
        if ((str2.length() == 15 || str2.length() == 18) && Pattern.compile("[0-9]+[0|1|2|3|4|5|6|7|8|9|X|x]$").matcher(str2).matches()) {
            return 0;
        }
        return 70001202;
    }

    private void ˊ(Context context) {
        this.ˊॱ = new djl(context);
        this.ˊॱ.ˋ(this.ᐝ.getString(exp$f.ˊʼ));
        this.ˊॱ.setCancelable(false);
        this.ˊॱ.setCanceledOnTouchOutside(false);
        this.ˊॱ.show();
        String obj = this.ॱˊ.getText().toString();
        String obj2 = this.ˏॱ.getText().toString();
        int ˎ = ˎ(obj, obj2);
        if (ˎ != 0) {
            ˏ(ˎ, false);
            return;
        }
        RealName realName = new RealName();
        realName.ˊ(obj);
        realName.ˏ(obj2);
        realName.ॱ(UserSession.getInstance().getUserId());
        new fap().ॱ(this.ᐝ, this.ʼ, realName, this.ʻ, this.ॱॱ);
    }

    private void ˎ(int i) {
        if (this.ˎ != null) {
            int height = (this.ˎ.getHeight() - this.ˋ.getHeight()) + i;
            if (height > 0) {
                int ॱ = ॱ(this.ᐝ);
                Dialog ˋ = ˋ();
                if (ˋ == null || ˋ.getWindow() == null) {
                    Logger.e("RealNameAuthDialog", "dialog == null || dialog.getWindow() == null || dialog.getWindow().getDecorView() == null");
                    return;
                }
                int height2 = ˋ.getWindow().getDecorView().getHeight();
                if (height2 <= ॱ) {
                    ॱ -= height2;
                    LayoutParams layoutParams = this.ˋ.getLayoutParams();
                    if (height > ॱ) {
                        layoutParams.height += ॱ;
                        height = height2 + ॱ;
                    } else {
                        layoutParams.height += height;
                        height += height2;
                    }
                    this.ˋ.setLayoutParams(layoutParams);
                    LayoutParams layoutParams2 = this.ॱ.getLayoutParams();
                    layoutParams2.height = layoutParams.height + epv.ˋ(this.ᐝ, 16);
                    this.ॱ.setLayoutParams(layoutParams2);
                    ॱ(height);
                    this.ˋ.smoothScrollBy(0, 10);
                }
            }
        }
    }

    private void ॱ(int i) {
        if (ˋ() != null) {
            Window window = ˋ().getWindow();
            if (window != null) {
                WindowManager.LayoutParams attributes = window.getAttributes();
                attributes.height = i;
                window.setAttributes(attributes);
            }
        }
    }

    private void ॱॱ() {
        String string = this.ᐝ.getString(exp$f.ˋ);
        Object string2 = this.ᐝ.getString(exp$f.ˉॱ, new Object[]{string});
        CharSequence spannableString = new SpannableString(string2);
        int lastIndexOf = string2.lastIndexOf(string);
        int length = string.length() + lastIndexOf;
        spannableString.setSpan(new ClickableSpan(this) {
            final /* synthetic */ fao ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                ((azj) fho.ˏ().ˋ("AGWebView").ॱ(azj.class)).ˋ(this.ˎ.ᐝ, "user_privacy_webview", cvx.ˎ("app.privacy.domain") + eqp.ॱ() + ContainerUtils.FIELD_DELIMITER + "language" + ContainerUtils.KEY_VALUE_DELIMITER + doi.ॱ(), false);
            }

            public void updateDrawState(TextPaint textPaint) {
                super.updateDrawState(textPaint);
                textPaint.setUnderlineText(false);
            }
        }, lastIndexOf, length, 33);
        spannableString.setSpan(new ForegroundColorSpan(this.ᐝ.getResources().getColor(exp$c.ˏ)), lastIndexOf, length, 34);
        this.ॱᐝ.setText(spannableString);
        this.ॱᐝ.setMovementMethod(LinkMovementMethod.getInstance());
        this.ॱᐝ.setHighlightColor(this.ᐝ.getResources().getColor(exp$c.ʻ));
    }

    private int ॱ(Context context) {
        if (context.getResources().getConfiguration().orientation == 2) {
            return (int) (0.9d * ((double) epv.ˎ(context)));
        }
        return (int) (0.8d * ((double) epv.ॱ(context)));
    }
}
